home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / data / ysuty2 / filetest.c < prev    next >
Text File  |  1993-07-08  |  2KB  |  76 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include <dos.h>
  6.  
  7. void main(int argc,char *argv[])
  8. {
  9.     int i,n;
  10.     char *atr[]={"","<DIR>"},*fn[64],sd[64],buf[64*14];
  11.  
  12.     if(argc<2)n=YSC_getDosFiles(fn,sd,64,"","",buf);
  13.          else n=YSC_getDosFiles(fn,sd,64,"",argv[1],buf);
  14.  
  15.     for(i=0; i<n; i++)
  16.     {
  17.         printf("%s   %s\n",fn[i],atr[sd[i]]);
  18.     }
  19. }
  20.  
  21.  
  22.  
  23. int YSC_getDosFiles(char *fn[],char *sd,int max,char *path,char *wc,char *buf)
  24. {
  25.     struct find_t dir;
  26.     int pl,i,n;
  27.     int rst;
  28.     char Path[128],tmn;
  29.  
  30.     if(*wc==0)wc="*.*";
  31.     pl=strlen(path);
  32.     tmn=path[pl-1];
  33.     if     (pl==0)                strcpy(Path,"*.*");
  34.     else if(tmn!='\\' && tmn!=':')sprintf(Path,"%s\\%s",path,"*.*");
  35.     else                          sprintf(Path,"%s%s",path,"*.*");
  36.  
  37.     n=0;
  38.     for(i=0; n<max ; i++)
  39.     {
  40.         if(i==0)rst=_dos_findfirst(Path,_A_SUBDIR,&dir);
  41.            else rst=_dos_findnext(&dir);
  42.         if(rst)break;
  43.  
  44.         if( dir.attrib & _A_SUBDIR )
  45.         {
  46.             strcpy(buf,dir.name);
  47.             fn[n]=buf;
  48.             sd[n]=1;
  49.             buf += strlen(dir.name)+1;
  50.             n++;
  51.         }
  52.     }
  53.  
  54.     if     (pl==0)                strcpy(Path,wc);
  55.     else if(tmn!='\\' && tmn!=':')sprintf(Path,"%s\\%s",path,wc);
  56.     else                          sprintf(Path,"%s%s",path,wc);
  57.  
  58.     for(i=0; n<max ; i++)
  59.     {
  60.         if(i==0)rst=_dos_findfirst(Path,_A_NORMAL,&dir);
  61.            else rst=_dos_findnext(&dir);
  62.         if(rst)break;
  63.  
  64.         if((dir.attrib & _A_SUBDIR)==0)
  65.         {
  66.             strcpy(buf,dir.name);
  67.             fn[n]=buf;
  68.             sd[n]=0;
  69.             buf += strlen(dir.name)+1;
  70.             n++;
  71.         }
  72.     }
  73.  
  74.     return n;
  75. }
  76.